import { join } from 'path';
import { ResponseInterceptor } from './interceptors/response.interceptor';
import { HttpExceptionFilter } from './filters/http-exception.filter';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { NestExpressApplication } from '@nestjs/platform-express';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  // 全局异常处理
  app.useGlobalFilters(new HttpExceptionFilter());
  // 全局返回拦截器
  app.useGlobalInterceptors(new ResponseInterceptor());
  // swagger ui
  const options = new DocumentBuilder()
    .setTitle('Imager Api')
    .setDescription('The Imager API description')
    .setVersion('1.0')
    .addTag('imager')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);
  // 跨域
  app.enableCors();
  // 静态资源转发
  app.useStaticAssets(join(__dirname, '.', 'upload'), {
    prefix: '/upload/',
  });
  await app.listen(3002);
}
bootstrap();
